home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / amigaoscd / amigapluscd / AP-Website / forum / wbboard / class_db_zugriff.php < prev    next >
PHP Script  |  2001-11-17  |  3KB  |  113 lines

  1. <?
  2. class db_zugriff {
  3.   
  4.   var $database = "";
  5.  
  6.   var $link_id  = 0;
  7.   var $query_id = 0;
  8.   var $record   = array();
  9.  
  10.   var $errdesc    = "";
  11.   var $errno   = 0;
  12.   var $show_error = 1;
  13.    
  14.   var $server   = "";
  15.   var $user     = "";
  16.   var $password = "";
  17.  
  18.   var $appname  = "WoltLab Burning Board";
  19.   
  20.     function connect() {
  21.             if ( 0 == $this->link_id ) {
  22.                   
  23.                   $this->link_id=mysql_connect($this->server,$this->user,$this->password);
  24.                   
  25.                   if (!$this->link_id) {
  26.                     $this->print_error("Link-ID == false, connect failed");
  27.                   }
  28.                   if ($this->database!="") {
  29.                     $this->select_db($this->database);
  30.                   }
  31.             }
  32.       }
  33.     
  34.     function geterrdesc() {
  35.             $this->error=mysql_error();
  36.             return $this->error;
  37.       }
  38.  
  39.       function geterrno() {
  40.             $this->errno=mysql_errno();
  41.             return $this->errno;
  42.       }
  43.  
  44.       function select_db($database="") {
  45.             if ($database!="") {
  46.               $this->database=$database;
  47.             }
  48.             if(!@mysql_select_db($this->database, $this->link_id)) {
  49.                   $this->print_error("cannot use database ".$this->database);
  50.             }
  51.       }
  52.  
  53.       function query($query_string) {
  54.             $this->query_id = mysql_query($query_string,$this->link_id);
  55.             if (!$this->query_id) {
  56.                   $this->print_error("Invalid SQL: ".$query_string);
  57.             }
  58.             return $this->query_id;
  59.       }
  60.  
  61.       function fetch_array($query_id=-1) {
  62.             if ($query_id!=-1) {
  63.                   $this->query_id=$query_id;
  64.             }
  65.             $this->record = mysql_fetch_array($this->query_id);
  66.  
  67.             return $this->record;
  68.       }
  69.  
  70.       function free_result($query_id=-1) {
  71.             if ($query_id!=-1) {
  72.                   $this->query_id=$query_id;
  73.             }
  74.             return @mysql_free_result($this->query_id);
  75.       }
  76.  
  77.       function query_first($query_string) {
  78.             $this->query($query_string);
  79.             $returnarray=$this->fetch_array($this->query_id);
  80.             $this->free_result($this->$query_id);
  81.             return $returnarray;
  82.       }
  83.  
  84.       function num_rows($query_id=-1) {
  85.             if ($query_id!=-1) {
  86.                   $this->query_id=$query_id;
  87.             }
  88.             return mysql_num_rows($this->query_id);
  89.       }
  90.  
  91.       function insert_id() {
  92.             return mysql_insert_id($this->link_id);
  93.       }
  94.  
  95.       function print_error($msg) {
  96.             $this->errdesc=mysql_error();
  97.             $this->errno=mysql_errno();
  98.             
  99.             global $adminmail;
  100.             $message="Database error in $this->appname: $msg\n<br>";
  101.             $message.="mysql error: $this->errdesc\n<br>";
  102.             $message.="mysql error number: $this->errno\n<br>";
  103.             $message.="Date: ".date("d.m.Y @ H:i")."\n<br>";
  104.             $message.="Script: ".getenv("REQUEST_URI")."\n<br>";
  105.             $message.="Referer: ".getenv("HTTP_REFERER")."\n<br><br>";
  106.  
  107.             if($this->show_error) $message = "$message";
  108.         else $message = "\n<!-- $message -->\n";
  109.               eval("dooutput(\"".gettemplate("db_error")."\");");
  110.               die("");
  111.         }
  112. }
  113.